/**
 *
 * wolive 浮层版 客服咨询js
 * [wolive description]
 * @return {[type]} [description]
 */

var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
    link.type='text/css';
    link.rel = 'stylesheet';
    link.href ='http://www.wolive.tt/assets/css/index/wolive_online.css';
    head.appendChild(link);

var wolive ={
     visiter_id:'',
     visiter_name:'',
     avatar:'',
     product:{},
     open:function(){
        var d =document.getElementById('wolive-box');
        if(!d){
        	var div =document.createElement('div');
        	div.id ="wolive-kefu";
        	div.className +='wolive-form';
        	document.body.appendChild(div);
        	var w =document.getElementById('wolive-kefu');
            w.innerHTML=' <i class="wolive-icon"></i><p class="wolive-item" onclick="wolive.connenct(0)" >在线咨询</p>';
        }

     },
     connenct:function(groupid){
       var id =groupid;
       if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
          
         window.open("http://www.wolive.tt/mobile/index?visiter_id="+this.visiter_id+"&visiter_name="+this.visiter_name+"&avatar="+this.avatar+"&business_id=admin&groupid="+groupid+"&product=", "_blank"); 
       
       }else{

       var s =document.getElementById('wolive-talk');
        
       if(!s){
            var div = document.createElement('div');
            div.id ="wolive-talk";
            div.title=id;
            document.body.appendChild(div);
            div.innerHTML='<i class="wolive-close" onclick="wolive.narrow()"></i><iframe id="wolive-iframe" src="http://www.wolive.tt/layer?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=admin&groupid='+groupid+'"></iframe>'
          
        }else{
            var div=document.getElementById('wolive-talk');
            var title =div.title;
            if(title == groupid){
                div.style ='display:block';
            }else{
                div.parentNode.removeChild(div);
                wolive.connenct(groupid); 
            }
        }
       }
     },
     narrow:function(){
        var div=document.getElementById('wolive-talk');
        div.style ='display:none';
     }
}

window.onload =wolive.open();
